import org.apache.ibatis.session.SqlSession;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import yunhe.biz.EmpMsgBiz;
import yunhe.biz.StockMgrBiz;
import yunhe.biz.impl.EmpMsgBizImpl;
import yunhe.biz.impl.StockMgrBizImpl;
import yunhe.dao.IStockMgrDao;
import yunhe.entity.*;
import yunhe.util.GeneralUtil;
import yunhe.util.SqlSessionFactoryUtil;

import java.sql.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/6/14.
 */
public class test {
    @Test
    public void testSeq() {
        System.out.println(GeneralUtil.creatSeq("pd"));
    }

    @Test
    public void testStock() {
        SqlSession ss = SqlSessionFactoryUtil.getSqlSession();
        IStockMgrDao imd = ss.getMapper(IStockMgrDao.class);
//        List<Inventory> li=imd.searchInv();
//        for (Inventory i:li){
//            System.out.println(i.getProduct().getProName());
//        }
        List<Inventory> o = imd.searchInvByPro("1111111111111");

    }

    @Test
    public void stockOut() {
        SqlSession ss = SqlSessionFactoryUtil.getSqlSession();
        IStockMgrDao imd = ss.getMapper(IStockMgrDao.class);
        EmpMsg empM = new EmpMsg();
        empM.setWorkId("100861");
        StockOut so = new StockOut();
        so.setStockOutsId(GeneralUtil.creatSeq("SO"));
        so.setStockOutDate(new Date(new java.util.Date().getTime()));
        so.setEmpMsg(empM);
        so.setStockReason("订单");
        System.out.println(imd.writeStockOut(so));


        StockOutAppend soa = new StockOutAppend();
        soa.setStockOut(so);
        soa.setProBarCode("1234567890123");
        soa.setStockOutQuantity(50);
        soa.setStoId("ck201606002220");
        System.out.println(imd.writeStockOutApp(soa));
    }

    @Test
    public void t1() {
        EmpMsgBiz emb = new EmpMsgBizImpl();
        List<EmpMsg> lem = emb.getAllEmp();
        JSONArray ja = new JSONArray();
        for (EmpMsg em : lem) {
            JSONObject jb = new JSONObject(em);
            ja.put(jb);
        }
        System.out.println(ja.toString());
    }

    @Test
    public void t2() throws JSONException {
        StockMgrBiz stock = new StockMgrBizImpl();
        //查出所有的仓库
        List<Storage> list_storage = stock.querySto();

        JSONArray ja = new JSONArray();

        for (Storage s : list_storage) {
            JSONArray jsa=new JSONArray();

            JSONObject jo=new JSONObject(s);
            System.out.println(jo.toString());
        }
    }
    @Test
    public void t3(){
        StockMgrBiz sb=new StockMgrBizImpl();
        List<Inventory> li=sb.searchInvByPro("1111111111111");
        JSONArray ja=new JSONArray();
        for (Inventory l:li){
            JSONObject jo=new JSONObject(l);
            ja.put(jo);
        }
        System.out.println(ja.toString());
    }

}
